home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / gui / toolbox / dnd.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  3KB  |  89 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import wx
  5. from util import do, Storage as S
  6. from logging import getLogger
  7. log = getLogger('dnd')
  8. drag_types = {
  9.     wx.DF_FILENAME: ('files', wx.FileDataObject, wx.FileDataObject.GetFilenames),
  10.     wx.DF_TEXT: ('text', wx.TextDataObject, wx.TextDataObject.GetText),
  11.     wx.DF_BITMAP: ('bitmap', wx.PyBitmapDataObject, wx.PyBitmapDataObject.GetBitmap) }
  12.  
  13. class SimpleDropTarget(wx.PyDropTarget):
  14.     accepts_default = (wx.DF_FILENAME, wx.DF_TEXT, wx.DF_BITMAP)
  15.     
  16.     def __init__(self, calltarget = None, accepts = accepts_default, **callbacks):
  17.         wx.PyDropTarget.__init__(self)
  18.         if not all((lambda .0: for c in .0:
  19. callable(c))(callbacks.values())):
  20.             raise TypeError, 'keyword arguments to DropTarget must be callable'
  21.         
  22.         self.dragged = wx.DataObjectComposite()
  23.         for dragtype in accepts:
  24.             (datatype, datainit, datamethod) = drag_types[dragtype]
  25.             obj = datainit()
  26.             self.dragged.Add(obj)
  27.             setattr(self.dragged, datatype, obj)
  28.         
  29.         self.SetDataObject(self.dragged)
  30.         self.accepts = accepts
  31.         self.calltarget = calltarget
  32.         self.callbacks = callbacks
  33.         self.successful_drag_result = wx.DragCopy
  34.  
  35.     
  36.     def callif(self, dragtype, data):
  37.         call = getattr(self.calltarget, 'OnDrop' + dragtype.title(), None)
  38.         if callable(call):
  39.             if dragtype == 'files':
  40.                 wx.CallLater(300, call, data)
  41.             else:
  42.                 call(data)
  43.         elif dragtype in self.callbacks:
  44.             if dragtype == 'files':
  45.                 wx.CallLater(300, self.callbacks[dragtype], data)
  46.             else:
  47.                 self.callbacks[dragtype](data)
  48.         else:
  49.             log.info('ignored (%s): %s', dragtype, repr(data)[:50])
  50.  
  51.     
  52.     def OnDrop(self, x, y):
  53.         return True
  54.  
  55.     
  56.     def OnData(self, x, y, d):
  57.         self.GetData()
  58.         format = self.dragged.GetReceivedFormat().GetType()
  59.         for format in self.accepts:
  60.             (datatype, datainit, datamethod) = drag_types[format]
  61.             data = datamethod(getattr(self.dragged, datatype))
  62.             if data:
  63.                 self.callif(datatype, data)
  64.                 continue
  65.         
  66.         return True
  67.  
  68.     
  69.     def OnEnter(self, x, y, d):
  70.         return d
  71.  
  72.     
  73.     def OnDragOver(self, x, y, d):
  74.         return wx.DragMove
  75.  
  76.  
  77. if __name__ == '__main__':
  78.     a = wx.PySimpleApp()
  79.     f = wx.Frame(None)
  80.     
  81.     def foo(data):
  82.         print data
  83.  
  84.     p = wx.Panel(f)
  85.     p.SetDropTarget(DropTarget(text = foo, files = foo, bitmap = foo))
  86.     f.Show(True)
  87.     a.MainLoop()
  88.  
  89.